﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class RoomCustomer : System.Web.UI.Page
{
    private SqlDataReader sdr = null;
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 100 and 200 )";
            Command(sql1);
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (DropDownList1.Text.Trim() == "一层")
            {
                string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 100 and 200 )";
                Command(sql1);
            }
            if (DropDownList1.Text.Trim() == "二层")
            {
                string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 200 and 300 )";
                Command(sql1);
            }
            if (DropDownList1.Text.Trim() == "三层")
            {
                string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 300 and 400 )";
                Command(sql1);
            }
            if (DropDownList1.Text.Trim() == "四层")
            {
                string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 400 and 500 )";
                Command(sql1);
            }
            if (DropDownList1.Text.Trim() == "五层")
            {
                string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 500 and 600 )";
                Command(sql1);
            }
            if (DropDownList1.Text.Trim() == "六层")
            {
                string sql1 = "select oroominfor.roomno,oroominfor.rtype,usr_infor.name,usr_infor.idcard,oroominfor.livedtime,oroominfor.rmoney1 from oroominfor, usr_infor where oroominfor.id = usr_infor.id and oroominfor.isorder = '是' and oroominfor.roomno in(select HM_RCategoryId from HM_RoomCategory WHERE HM_RCategoryId between 600 and 700 )";
                Command(sql1);
            }
        }
        catch
        {
            Response.Write("<script>alert('查询失败，请查看相关代码！')</script>");
        }
        finally
        {
            sdr.Close();
        }
    }
    protected void Command(string sql)
    {
        sqlhelper.conn.Open();
        SqlCommand cmd = new SqlCommand(sql, sqlhelper.conn);
        sdr = cmd.ExecuteReader();
        dt.Load(sdr);
        try
        {
            if (dt.Rows.Count == 0)
            {
                Response.Write("<script>alert('相关楼层没有客户入住！')</script>");
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }
        catch
        {
            Response.Write("<script>alert('查询失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }

    }

    protected void Set_Days_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql = "update oroominfor set livedtime=livedtime+'" + Days.Text.Trim() + "',rmoney1=oroominfor.rmoney1+oroominfor.rmoney*'" + Days.Text.Trim() + "'";
            SqlCommand cmd = new SqlCommand(sql, sqlhelper.conn);
            cmd.ExecuteNonQuery();
        }
        catch
        {
            Response.Write("<script>alert('设置失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }

    protected void Set_Money_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql1 = "select sum(rmoney1) from oroominfor";
            SqlCommand cmd1 = new SqlCommand(sql1, sqlhelper.conn);
            SqlDataReader sdr = cmd1.ExecuteReader();
            while (sdr.Read())
            {
                Money.Text = sdr[0].ToString();
            }
            sdr.Close();
        }
        catch
        {
            Response.Write("<script>alert('获取失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }
}